package com.macro.mall.controller;

import com.macro.mall.dto.OmsReturnApplyQueryParam;
import com.macro.mall.dto.OmsUpdateStatusParam;
import com.macro.mall.service.OmsOrderReturnApplyService;
import com.macro.model.OmsOrderReturnApply;
import common.api.CommonPage;
import common.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "订单退货申请管理",tags = "退货模块")
@Controller
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {

    @Autowired
    private OmsOrderReturnApplyService returnApplyService;

    /**
     * 查询所有退货申请
     */
    @ApiOperation("分页查询退货申请")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<OmsOrderReturnApply>> list(OmsReturnApplyQueryParam queryParam,
                                                        @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize){
        List<OmsOrderReturnApply> list = returnApplyService.list(queryParam, pageNum, pageSize);

        return CommonResult.success(CommonPage.restPage(list));
    }

    /**
     *  批量删除退货申请
     */
    @ApiOperation("批量删除申请")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delete(@RequestParam("ids") List<Long> ids){
        int count = returnApplyService.delete(ids);
        if(count > 0)
            return CommonResult.success(count);
        return CommonResult.failed();
    }

    /**
     * 获取退货申请详情
     */
    @ApiOperation("获取退货申请详情")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult getItem(@PathVariable("id") Long id){
        return CommonResult.success(returnApplyService.getItem(id));
    }


    /**
     * 修改申请状态
     */
    @ApiOperation("修改申请状态")
    @RequestMapping(value = "/update/status/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updateStatus(@PathVariable("id") Long id,
                                     @RequestBody OmsUpdateStatusParam statusParam){
        int count = returnApplyService.updateStatus(id,statusParam);
        if(count > 0)
            return CommonResult.success(count);
        return CommonResult.failed();
    }
}
